package com.xnyzc.lhy.didi.service.impl.order;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.xnyzc.lhy.common.component.didi.DiDiUrlConstant;
import com.xnyzc.lhy.common.component.redis.RedisCommon;
import com.xnyzc.lhy.common.constant.MqConstant;
import com.xnyzc.lhy.common.constant.RedisPrefixConstant;
import com.xnyzc.lhy.common.entity.DiDiRv;
import com.xnyzc.lhy.common.exception.DiDiException;
import com.xnyzc.lhy.common.penum.EDiDiErrorCode;
import com.xnyzc.lhy.common.penum.EDispatchType;
import com.xnyzc.lhy.common.penum.EOrderType;
import com.xnyzc.lhy.common.penum.order.EDiDiOrderStatus;
import com.xnyzc.lhy.common.penum.order.EOrderOtherPrice;
import com.xnyzc.lhy.common.penum.vehicle.ECallVehType;
import com.xnyzc.lhy.common.util.CheckUtil;
import com.xnyzc.lhy.common.util.IDUtil;
import com.xnyzc.lhy.common.util.RequestMethodUtil;
import com.xnyzc.lhy.common.util.sign.AttestationTool;
import com.xnyzc.lhy.didi.entity.dict.OaSysDict;
import com.xnyzc.lhy.didi.entity.order.OaCOrderPersonal;
import com.xnyzc.lhy.didi.entity.order.OaOrderOtherPrice;
import com.xnyzc.lhy.didi.entity.param.order.CreateOrderParam;
import com.xnyzc.lhy.didi.entity.param.order.OrderDetailParam;
import com.xnyzc.lhy.didi.entity.price.OaSysBillRules;
import com.xnyzc.lhy.didi.entity.results.didi.order.OrderDetailResults;
import com.xnyzc.lhy.didi.entity.results.didi.order.OrderStatusResults;
import com.xnyzc.lhy.didi.entity.results.order.BillDetailsListResults;
import com.xnyzc.lhy.didi.entity.results.order.BillDetailsResults;
import com.xnyzc.lhy.didi.entity.results.order.CreateOrderResults;
import com.xnyzc.lhy.didi.entity.results.order.QueryOrderStatusResults;
import com.xnyzc.lhy.didi.entity.results.order.RealTimeFeeListResults;
import com.xnyzc.lhy.didi.entity.results.order.RealTimeFeeResults;
import com.xnyzc.lhy.didi.feign.mq.IMqService;
import com.xnyzc.lhy.didi.mapper.dict.OaSysDictMapper;
import com.xnyzc.lhy.didi.mapper.order.OaCOrderPersonalMapper;
import com.xnyzc.lhy.didi.mapper.order.OaOrderOtherPriceMapper;
import com.xnyzc.lhy.didi.mapper.price.OaSysBillRulesMapper;
import com.xnyzc.lhy.didi.mq.MQProducer;
import com.xnyzc.lhy.didi.service.order.OrderCorrelationService;
import com.xnyzc.lhy.order.entity.system.OaSysDispatchLog;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 订单相关
 * </p>
 *
 * @author zhengxu
 * @since 2019-09-25
 */
@Slf4j
@Service
public class OrderCorrelationServiceImpl implements OrderCorrelationService {

    @Autowired
    private OaCOrderPersonalMapper oaCOrderPersonalMapper;

    @Autowired
    private OaSysDictMapper oaSysDictMapper;

    @Autowired
    private OaOrderOtherPriceMapper oaOrderOtherPriceMapper;

    @Autowired
    private OaSysBillRulesMapper oaSysBillRulesMapper;

    @Autowired
    private RedisCommon redisCommon;

    @Autowired
    private IMqService iMqService;

    @Autowired
    private MQProducer producer;

    /**
     * 查询订单详情(包含状态修改，数据添加)
     *
     * @param param 入参实体
     * @return
     */
    @Override
    public DiDiRv getOrderDetail(OrderDetailParam param) {
        OrderDetailResults results = new OrderDetailResults();
        String data = orderCorrelation(param, DiDiUrlConstant.ORDER_DETAIL_API);
        if (CheckUtil.strIsEmpty(data)) {
            throw DiDiException.create(EDiDiErrorCode.httpRequestDidiUrlError);
        }
        JSONObject jsonObject = JSONObject.parseObject(data);
        if (CheckUtil.objIsNotEmpty(jsonObject) && jsonObject.get(DiDiUrlConstant.ERRNO).equals(EDiDiErrorCode.success.getValue())) {
            JSONObject dataObject = jsonObject.getJSONObject("data");
            OaCOrderPersonal personal = getOaCOrderPersonalVersion(param);
            // 修改订单表
            UpdateWrapper<OaCOrderPersonal> updateWrapper = new UpdateWrapper<>();
            if (StringUtils.isNotBlank(dataObject.getString("status"))) {
                results.setStatus(dataObject.getString("status"));
                getOrderStatus(personal, results.getStatus());
            }
            if (StringUtils.isNotBlank(dataObject.getString("passenger_phone"))) {
                results.setPassenger_phone(dataObject.getString("passenger_phone"));
                updateWrapper.set(OaCOrderPersonal.PASSENGER_PHONE, results.getPassenger_phone());
            }
            if (StringUtils.isNotBlank(dataObject.getString("passenger_phone_suffix"))) {
                results.setPassenger_phone_suffix(dataObject.getString("passenger_phone_suffix"));
                updateWrapper.set(OaCOrderPersonal.PASSENGER_PHONE_SUFFIX, results.getPassenger_phone_suffix());
            }
            updateWrapper.set(OaCOrderPersonal.VERSION, personal.getVersion() + 1);
            updateWrapper.set(OaCOrderPersonal.UPDATE_TIME, new Date());
            updateWrapper.eq(OaCOrderPersonal.ORDER_NO, param.getOrder_id());
            updateWrapper.eq(OaCOrderPersonal.VERSION, personal.getVersion());
            try {
                int update = oaCOrderPersonalMapper.update(null, updateWrapper);
                if (update < 1) {
                    throw DiDiException.create(EDiDiErrorCode.orderPersonalUpdateFail);
                }
            } catch (Exception e) {
                log.error(e.getMessage());
                throw DiDiException.create(EDiDiErrorCode.orderPersonalUpdateFail);
            }
            return DiDiRv.wrap(EDiDiErrorCode.success, results);
        } else {
            throw DiDiException.create(EDiDiErrorCode.serverError);
        }
    }

    /**
     * 查询字典表中的订单状态
     *
     * @return
     */
    private List<OaSysDict> getOrderDictList(String status) {
        QueryWrapper<OaSysDict> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(OaSysDict.TYPE, "didi_order_status");
        queryWrapper.eq(OaSysDict.VALUE, status);
        List<OaSysDict> orderDictList = oaSysDictMapper.selectList(queryWrapper);
        return orderDictList;
    }

    /**
     * 订单状态查询（单纯查询）
     *
     * @param param 入参实体
     * @return
     */
    @Override
    public DiDiRv getOrderStatus(OrderDetailParam param) {
        OrderStatusResults results = new OrderStatusResults();
        String data = orderCorrelation(param, DiDiUrlConstant.ORDER_STATUS_API);
        if (CheckUtil.strIsEmpty(data)) {
            throw DiDiException.create(EDiDiErrorCode.httpRequestDidiUrlError);
        }
        JSONObject jsonObject = JSONObject.parseObject(data);
        if (jsonObject.get(DiDiUrlConstant.ERRNO).equals(EDiDiErrorCode.success.getValue())) {
            JSONObject dataObject = jsonObject.getJSONObject("data");
            OaCOrderPersonal personal = getOaCOrderPersonalVersion(param);
            if (StringUtils.isNotBlank(dataObject.getString("status"))) {
                results.setStatus(dataObject.getString("status"));
                getOrderStatus(personal, results.getStatus());
            }
            return DiDiRv.wrap(EDiDiErrorCode.success, results);
        }
        try {
            return JSONObject.parseObject(data, DiDiRv.class);
        } catch (Exception e) {
            log.error(e.getMessage());
            throw DiDiException.create(EDiDiErrorCode.DiDiGrabServerError);
        }
    }

    /**
     * 查询version
     *
     * @param param 查询参数
     * @return OaCOrderPersonal
     */
    private OaCOrderPersonal getOaCOrderPersonalVersion(OrderDetailParam param) {
        // 查询version
        QueryWrapper<OaCOrderPersonal> queryVersion = new QueryWrapper<>();
        queryVersion.select(OaCOrderPersonal.VERSION);
        queryVersion.eq(OaCOrderPersonal.ORDER_NO, param.getOrder_id());
        List<OaCOrderPersonal> oaCOrderPersonals = oaCOrderPersonalMapper.selectList(queryVersion);
        if (CheckUtil.collectionIsEmpty(oaCOrderPersonals)) {
            throw DiDiException.create(EDiDiErrorCode.orderPersonalSelectFail);
        }
        return oaCOrderPersonals.get(0);
    }

    /**
     * 获取订单的状态
     *
     * @param personal
     * @param status
     * @return
     */
    public void getOrderStatus(OaCOrderPersonal personal, String status) {
        if (StringUtils.isNotBlank(status)) {
            EDiDiOrderStatus byDidiType = EDiDiOrderStatus.findByDidiType(Integer.valueOf(status));
            if (CheckUtil.objIsNotEmpty(personal)) {
                personal.setOrderStatus(byDidiType.getType());
                personal.setDidiOrderStatus(byDidiType.getDidiType());
            }
        }
    }


    /**
     * 下听订单实时账单
     *
     * @param param 入参实体
     * @return
     */
    @Override
    public DiDiRv pGetRealTimeFeeDetail(OrderDetailParam param) {
        RealTimeFeeResults details = new RealTimeFeeResults();
        String data = orderCorrelation(param, DiDiUrlConstant.REAL_TIME_FEE_API);
        JSONObject jsonObject = JSONObject.parseObject(data);
        if (jsonObject.get(DiDiUrlConstant.ERRNO).equals(EDiDiErrorCode.success.getValue())) {
            JSONObject dataObject = jsonObject.getJSONObject("data");
            // 存值
            details.setDriver_metre(dataObject.getBigDecimal("driver_metre"));
            details.setDriver_minute(dataObject.getBigDecimal("driver_minute"));
            JSONArray price_list = dataObject.getJSONArray("price_list");
            List<RealTimeFeeListResults> priceList = new ArrayList<>();
            RealTimeFeeListResults results = new RealTimeFeeListResults();
            results.setStart_fee(price_list.getJSONObject(0).getBigDecimal("start_fee"));
            results.setNormal_fee(price_list.getJSONObject(0).getBigDecimal("normal_fee"));
            results.setTime_fee(price_list.getJSONObject(0).getBigDecimal("time_fee"));
            results.setEmpty_fee(price_list.getJSONObject(0).getBigDecimal("empty_fee"));
            results.setTime_rate_fee(price_list.getJSONObject(0).getBigDecimal("time_rate_fee"));
            results.setUrgent_fee(price_list.getJSONObject(0).getBigDecimal("urgent_fee"));
            results.setEmpty_distance(price_list.getJSONObject(0).getBigDecimal("empty_distance"));
            results.setHighway_fee(price_list.getJSONObject(0).getBigDecimal("highway_fee"));
            results.setNormal_distance(price_list.getJSONObject(0).getBigDecimal("normal_distance"));
            results.setNormal_time(price_list.getJSONObject(0).getInteger("normal_time"));
            results.setBridge_fee(price_list.getJSONObject(0).getBigDecimal("bridge_fee"));
            results.setPark_fee(price_list.getJSONObject(0).getBigDecimal("park_fee"));
            results.setOther_fee(price_list.getJSONObject(0).getBigDecimal("other_fee"));
            results.setTotal_fee(price_list.getJSONObject(0).getBigDecimal("total_fee"));
            priceList.add(results);
            details.setPrice_list(priceList);
        }
        return DiDiRv.wrap(EDiDiErrorCode.success, details);
    }

    /**
     * 处理订单
     *
     * @param param
     */
    public String orderCorrelation(OrderDetailParam param, String urlSuffix) {
        if (StringUtils.isBlank(param.getOrder_id()) || StringUtils.isBlank(param.getOpen_oid())) {
            throw DiDiException.create(EDiDiErrorCode.parameterError);
        }
        String url = DiDiUrlConstant.didiUrl + urlSuffix;
        param.setApp_id(DiDiUrlConstant.didiAppId);
        param.setSign(DiDiUrlConstant.didiSignPro);
        Date date = new Date();
        String timestamp = String.valueOf(date.getTime() / 1000);
        param.setTimestamp(timestamp);
        String signParameter = AttestationTool.getSign(param, DiDiUrlConstant.X_WWW_FORM_URLENCODED);
        // 请求滴滴
        return RequestMethodUtil.requestMethod(signParameter, url);
    }

    /**
     * 创建订单
     *
     * @return
     */
    @Override
    public DiDiRv getCreateOrder(CreateOrderParam param) {
        CreateOrderResults priceParam = new CreateOrderResults();
        if (StringUtils.isBlank(param.getOpen_oid()) || StringUtils.isBlank(param.getOpen_pid()) || StringUtils.isBlank(param.getEstimate_id())) {
            return DiDiRv.wrap(EDiDiErrorCode.success, priceParam);
        }
        OaSysBillRules rules = oaSysBillRulesMapper.selectById(param.getEstimate_id());
        if (CheckUtil.objIsEmpty(rules)) {
            return DiDiRv.wrap(EDiDiErrorCode.success, priceParam);
        }
        Long personalId = IDUtil.nextId();
        // 生成订单
        String orderNo = orderNo();
        OaCOrderPersonal personal = new OaCOrderPersonal();
        personal.setPersonalId(personalId);
        personal.setIsCarpool(0);
        personal.setOrderStatus(EDiDiOrderStatus.waitingResponse.getType());
        personal.setVehicleType(rules.getVehicleType());
        personal.setOrderNo(orderNo);
        personal.setDidiOrderId(param.getOpen_oid());
        personal.setDidiUserId(param.getOpen_pid());
        personal.setVersion(1L);
        personal.setCreateTime(new Date());
        personal.setCreateUser(param.getOpen_pid());
        personal.setUpdateTime(new Date());
        personal.setUpdateUser(param.getOpen_pid());
        personal.setRulesId(Long.valueOf(param.getEstimate_id()));
        oaCOrderPersonalMapper.insert(personal);
        priceParam.setOpen_oid(param.getOpen_oid());
        priceParam.setOrder_id("1");
        //priceParam.setOrder_id(String.valueOf(personalId));
        return DiDiRv.wrap(EDiDiErrorCode.success, priceParam);
    }

    /**
     * 创建订单开发版本
     *
     * @param createOrderParam 创建订单
     * @return DiDiRv
     */
    @Override
    public DiDiRv getCreateOrderReal(CreateOrderParam createOrderParam) {
        if (StringUtils.isBlank(createOrderParam.getOpen_oid()) || StringUtils.isBlank(createOrderParam.getOpen_pid()) || StringUtils.isBlank(createOrderParam.getEstimate_id())
                || StringUtils.isBlank(createOrderParam.getApp_id()) || StringUtils.isBlank(createOrderParam.getTimestamp()) || StringUtils.isBlank(createOrderParam.getSign())) {
            return DiDiRv.wrapError(EDiDiErrorCode.parameterError);
        }
        Long time = System.currentTimeMillis();
        // 获取估价单
        String estimateKey = RedisPrefixConstant.DIDI_ESTIMATE + createOrderParam.getEstimate_id();
        HashMap<String, Object> hashMap = redisCommon.getHashMap(estimateKey);
        // 生成新的订单ID
        String orderNo = orderNo();
        createOrderParam.setOrderNo(orderNo);
        long personalId = IDUtil.nextId();
        createOrderParam.setPersonalId(personalId);
        // 订单orderNo
        if (hashMap == null) {
            log.error("Redis中没有预估价格，创建订单失败！");
            return DiDiRv.wrapErrorCode(EDiDiErrorCode.orderCreateFail);
        }
        // 将MQ服务间调用更改为直发
        producer.sendMsg(createOrderParam, MqConstant.DIDI_CREATE_ORDER, null);
//        producer.createDidiOrder(createOrderParam);
        Map<String, String> map = new HashMap<>(4);
        map.put("order_id", orderNo);
        map.put("open_oid", createOrderParam.getOpen_oid());
        log.info("创建订单接口返回成功");
        //创建订单
        try {
            OaSysDispatchLog dispatchLog = new OaSysDispatchLog();
            dispatchLog.setType(EDispatchType.createOrderBefore.getType());
            dispatchLog.setOrderId(orderNo);
            dispatchLog.setTimestamp(time);
            dispatchLog.setLogId(IDUtil.nextId());
            dispatchLog.setCityId(hashMap.get("cityCode").toString());
            producer.sendMsg(dispatchLog, EDispatchType.createOrderBefore.getDesc(), "LHY_EVENT");
        } catch (Exception e) {
            log.error("记录订单调度日志!");
        }
        return DiDiRv.wrapSuccess(map);
    }

    /**
     * 获取订单ID
     *
     * @return
     */
    public static String orderNo() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
        //当前时间
        String date = simpleDateFormat.format(new Date());
        //当前类型
        String orderType = EOrderType.ZFJC.getValue();
        long s = (long) ((Math.random() * 9 + 1) * 100000000);
        return orderType + date + s;
    }


    /**
     * 取消订单
     *
     * @param param 入参实体
     * @return
     */
    @Override
    public DiDiRv cancelOrder(OrderDetailParam param) {
        if (StringUtils.isBlank(param.getOrder_id()) || StringUtils.isBlank(param.getOpen_oid())) {
            return DiDiRv.wrapErrorCode(EDiDiErrorCode.parameterError);
        }
        // 取消订单修改状态
        producer.sendMsg(param, MqConstant.DIDI_CANCEL_ORDER, null);
//        iMqService.updateOrderPersonalStatus(param);
        return DiDiRv.wrapSuccess(new Object());
    }

    /**
     * 查询订单状态
     *
     * @param param 入参实体
     * @return
     */
    @Override
    public DiDiRv queryOrderStatus(OrderDetailParam param) {

        QueryOrderStatusResults results = new QueryOrderStatusResults();
        if (StringUtils.isBlank(param.getOrder_id()) || StringUtils.isBlank(param.getOpen_oid())) {
            return DiDiRv.wrap(EDiDiErrorCode.parameterError, results);
        }

        // 查询订单信息
        try {
            OaCOrderPersonal order = iMqService.billDetails(param.getOrder_id());
            results.setStatus(String.valueOf(order.getDidiOrderStatus()));
            // 订单状态
            return DiDiRv.wrap(EDiDiErrorCode.success, results);
        } catch (Exception e) {
            throw DiDiException.create(EDiDiErrorCode.orderPersonalSelectFail);
        }
    }

    /**
     * 账单详情
     *
     * @param param 入参实体
     * @return
     */
    @Override
    public DiDiRv billDetails(OrderDetailParam param) {

        BillDetailsResults billDetails = new BillDetailsResults();

        if (StringUtils.isBlank(param.getOrder_id()) || StringUtils.isBlank(param.getOpen_oid())) {
            return DiDiRv.wrap(EDiDiErrorCode.parameterError, billDetails);
        }
        // 查询订单,首先从redis中获取如果redis中可以获取到
        OaCOrderPersonal order = null;
        String str = redisCommon.getStr(RedisPrefixConstant.ORDER_OA_D_ORDER + param.getOrder_id());
        if (CheckUtil.strIsNotEmpty(str)) {
            order = JSON.parseObject(str, OaCOrderPersonal.class);
        } else {
            QueryWrapper<OaCOrderPersonal> queryWrapper = new QueryWrapper<>();
            queryWrapper.select(OaCOrderPersonal.DIDI_ORDER_STATUS,
                    OaCOrderPersonal.MILEAGE_FEE, OaCOrderPersonal.MILAGE_DISTANCE,
                    OaCOrderPersonal.DURATION_TIME, OaCOrderPersonal.DURATION_FEE,
                    OaCOrderPersonal.DISTANCE_FEE, OaCOrderPersonal.PEAK_ADD_FEE,
                    OaCOrderPersonal.SPECIAL_PERIOD_FEE, OaCOrderPersonal.EMPTY_DISTANCE,
                    OaCOrderPersonal.BASE_FEE, OaCOrderPersonal.BASE_SUPPLEMENT_FEE,
                    OaCOrderPersonal.START_FEE, OaCOrderPersonal.TOTAL_FEE
            );
            queryWrapper.eq(OaCOrderPersonal.ORDER_NO, param.getOrder_id());
            order = oaCOrderPersonalMapper.selectOne(queryWrapper);
        }
        if (CheckUtil.objIsEmpty(order)) {
            return DiDiRv.wrap(EDiDiErrorCode.parameterError, billDetails);
        }
        // 设置订单状态
        billDetails.setStatus(String.valueOf(order.getDidiOrderStatus()));
        // 实时行驶距离
        billDetails.setDriver_metre(order.getDurationTime());
        // 实时行驶时间
        billDetails.setDriver_minute(order.getMilageDistance());
        List<BillDetailsListResults> priceList = new ArrayList<>();
        BillDetailsListResults results = new BillDetailsListResults();
        // 起步价(起步价模式必传；基础费模式不传，或者为0)
        // 起步价、里程费、时长费、远途费
        BigDecimal startFee = order.getStartFee();
        results.setStart_fee(startFee);
        results.setNormal_fee(order.getMileageFee());
        results.setTime_fee(order.getDurationFee());
        results.setEmpty_fee(order.getDistanceFee());
        results.setUrgent_fee(order.getPeakAddFee());
        // 其他费用、过桥费、停车费、高速费、普通时段计费时间
        BigDecimal otherMoney = new BigDecimal(0);
        BigDecimal bridgeMoney = new BigDecimal(0);
        BigDecimal parkMoney = new BigDecimal(0);
        BigDecimal highwayMoney = new BigDecimal(0);
        // 特殊时段费、远途行驶距离、基础费、基础费补足、计价行驶距离、普通时段计费时间
        if (CheckUtil.objIsNotEmpty(order.getSpecialPeriodFee())) {
            // 如果存在特殊时段费，保存
            results.setTime_rate_fee(order.getSpecialPeriodFee());
        }
        //获取远途里程(m)
        BigDecimal emptyDistance = order.getEmptyDistance();
        if (CheckUtil.objIsEmpty(emptyDistance)) {
            emptyDistance = new BigDecimal(0);
        }
        results.setEmpty_distance(BigDecimal.valueOf(emptyDistance.doubleValue() * 1000));
        results.setLimit_fee(order.getBaseFee());
        results.setLimit_pay(order.getBaseSupplementFee());
        //获取里程(m)
        BigDecimal milageDistance = order.getMilageDistance();
        if (CheckUtil.objIsEmpty(milageDistance)) {
            milageDistance = new BigDecimal(0);
        }
        results.setNormal_distance(BigDecimal.valueOf(milageDistance.doubleValue() * 1000));
        //获取时长(s)
        BigDecimal durationTime = order.getDurationTime();
        if (CheckUtil.objIsEmpty(durationTime)) {
            durationTime = new BigDecimal(0);
        }
        results.setNormal_time(durationTime.intValue() * 60);
        // 查询其他费用
        QueryWrapper otherFeeQueryWrapper = new QueryWrapper<>();
        otherFeeQueryWrapper.select(OaOrderOtherPrice.COST_TYPE, OaOrderOtherPrice.COST_AMOUNT);
        otherFeeQueryWrapper.eq(OaOrderOtherPrice.ORDER_NO, param.getOrder_id());
        List<OaOrderOtherPrice> oaOrderOtherPrices = oaOrderOtherPriceMapper.selectList(otherFeeQueryWrapper);
        // 其他费用
        if (CheckUtil.collectionIsNotEmpty(oaOrderOtherPrices)) {
            for (OaOrderOtherPrice otherPrice : oaOrderOtherPrices) {
                if (otherPrice.getCostType().equals(EOrderOtherPrice.bridgeToll.getType())) {
                    bridgeMoney = bridgeMoney.add(otherPrice.getCostAmount());
                } else if (otherPrice.getCostType().equals(EOrderOtherPrice.parkingFee.getType())) {
                    parkMoney = parkMoney.add(otherPrice.getCostAmount());
                } else if (otherPrice.getCostType().equals(EOrderOtherPrice.otherFee.getType())) {
                    otherMoney = otherMoney.add(otherPrice.getCostAmount());
                } else if (otherPrice.getCostType().equals(EOrderOtherPrice.highSpeedFee.getType())) {
                    highwayMoney = highwayMoney.add(otherPrice.getCostAmount());
                }
            }
        }
        results.setHighway_fee(highwayMoney);
        results.setBridge_fee(bridgeMoney);
        results.setPark_fee(parkMoney);
        results.setOther_fee(otherMoney);
        //如果总金额大于起步价,显示总金额,如果小于起步价显示起步价
        BigDecimal totalFee = order.getTotalFee();
        BigDecimal showFee = startFee;
        if (showFee.doubleValue() < totalFee.doubleValue()) {
            showFee = totalFee;
        }
        results.setTotal_fee(showFee);
        priceList.add(results);
        billDetails.setPrice_list(priceList);
        return DiDiRv.wrap(EDiDiErrorCode.success, billDetails);
    }

}
